<template>
	<view>
		<uni-notice-bar show-icon text="密码生成后自动复制!(本地缓存,无数据库,gitee开源<原密码>)" />
		<view class="container" style="padding:2px ;">
			<uni-group>
			<view class="uni-form-item uni-column">
				<button open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber">获取电话号码（未验证）</button>
				<button class="uni-button" type="primary" @click="ocrtest">身份证识别（验证成功）</button>
				<button class="uni-button" type="primary" @click="wxpay">微信支付（未验证）</button>
				<button class="uni-button" type="primary" @click="sendSMS">发送短信</button>
				
			</view>
			</uni-group>
			
		
		</view>
	</view>
</template>

<script>
	export default {
		
		data() {
			return {
				app_name:['steam','steam2','QQ','QQ2','门锁','门锁2','A密码','B密码','C密码','D密码','E密码','F密码','G密码','H密码','github','gitee','慕课','JD','微信','其他'],
				placeholderStyle: "color:#2979FF;font-size:14px",
				styles: {
					color: '#2979FF',
					borderColor: '#2979FF'
				},
				new_password:'',
				orgin_password:'',
				password_number:8,
				name:'',
				auth:false
			}
		},
		
		onLaunch: function() {
			console.log('App Launch')
		},
		onShow: function() {

		},
		onHide: function() {

		},
		methods: {
			// 身份证识别
			ocrtest(){
				uni.request({
				    url: 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=&secret=', //仅为示例，并非真实接口地址。
				    data: {
				        text: 'uni.request'
				    },
				    header: {
				        'custom-header': 'hello' //自定义请求头信息
				    },
				    success: (res) => {
						console.log(res);
						console.log(res.data);
						// return false;
						uni.chooseImage({
						    success: (chooseImageRes) => {
						        const tempFilePaths = chooseImageRes.tempFilePaths;
						        uni.uploadFile({
						            url: 'https://api.weixin.qq.com/cv/ocr/idcard?type=Front&access_token='+res.data.access_token,
						            filePath: tempFilePaths[0],
						            name: 'img',
						            formData: {
						            	contentType: 'image/png',
						            	value: "",
						            },
						            success: (a) => {
						            	let data = JSON.parse(a.data)
										console.log(data);
						            	if (data.errcode == 0) {
						            		
						            	} else if (data.errcode == '101001') {
						            		uni.showToast({
						            			title: "图片中无法找到证件!",
						            			icon: 'none',
						            			duration: 2000
						            		});
						            	} else if (data.errcode == '-1') {
						            		uni.showToast({
						            			title: "系统错误，请稍后重试!",
						            			icon: 'none',
						            			duration: 2000
						            		});
						            	} else if (data.errcode == '101002') {
						            		uni.showToast({
						            			title: "图片数据无效!",
						            			icon: 'none',
						            			duration: 2000
						            		});
						            	} else if (data.errcode == '101000') {
						            		uni.showToast({
						            			title: "图片URL错误或拉取URL图像错误!",
						            			icon: 'none',
						            			duration: 2000
						            		});
						            	}	
						            }
						        });
						    }
						});
						
						console.log(res);
						console.log(res.data);
						// this.text = 'request success';
					}	
				    
				});
						

			},
			
			getPhoneNumber (e) {
			    console.log(e.detail.code)
				// uni.request({
				//     url: 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=&secret=', //仅为示例，并非真实接口地址。
				//     data: {
				//         text: 'uni.request'
				//     },
				//     header: {
				//         'custom-header': 'hello' //自定义请求头信息
				//     },
				//     success: (res) => {
				// 		// uni.request({
				// 		//     url: 'https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=ACCESS_TOKEN', //仅为示例，并非真实接口地址。
				// 		//     data: {
				// 		//         code: 'uni.request'
				// 		//     },
				// 		//     header: {
				// 		//         'custom-header': 'hello' //自定义请求头信息
				// 		//     },
				// 		//     success: (res) => {
								
				// 		// 		https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=ACCESS_TOKEN
				// 		// 		console.log(res);
				// 		//         console.log(res.data);
				// 		//         // this.text = 'request success';
				// 		//     }
				// 		// });
						
						
				// 		console.log(res);
				//         console.log(res.data);
				//         // this.text = 'request success';
				//     }
				// });
			  },
			  
			  // https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/cloudbase/cloudbase.sendSms.html
			  sendSMS(){
				uni.request({
				    url: 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=&secret=', //仅为示例，并非真实接口地址。
				    data: {
				        text: 'uni.request'
				    },
				    header: {
				        'custom-header': 'hello' //自定义请求头信息
				    },
				    success: (res) => {
						console.log(res);
						console.log(res.data);
						uni.request({
						    url: 'https://api.weixin.qq.com/tcb/sendsms?access_token='+res.data.access_token, //仅为示例，并非真实接口地址。
						    data: {

						          "env":"online-12345678910",
						          "phone_number_list":[
						             "+8618728494292"
						          ],
						          "sms_type": "Marketing",
						          "content":"发布了新的能力",
						          "path":"/index.html",
						          "use_short_name": true
						    },
							method:"POST",
						    header: {
						        'custom-header': 'hello' //自定义请求头信息
						    },
						    success: (res) => {
								
								console.log(res);
						        console.log(res.data);
						        // this.text = 'request success';
						    }
						});
					}	
				    
				});
				

			  }
		}
	}
</script>

<style>
	.container {
		padding: 20px;
		font-size: 14px;
		line-height: 24px;
	}
</style>
